package net.sf.midollo.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class DefaultIOStream implements IOStream {

	protected final InputStream is;
	protected final OutputStream os;

	public DefaultIOStream(InputStream is, OutputStream os) {
		if (is == null)
			is = IOUtils.NULL_INPUT;
		if (os == null)
			os = IOUtils.NULL_OUTPUT;
		this.is = is;
		this.os = os;
	}

	public InputStream getInput() throws IOException {
		return this.is;
	}

	public OutputStream getOutput() throws IOException {
		return this.os;
	}

	public void close() throws IOException {
		IOException error = null;
		try {
			this.is.close();
		} catch (IOException e) {
			error = e;
		}
		try {
			this.os.close();
		} catch (IOException e) {
			if (error == null)
				error = e;
		}
		if (error != null)
			throw error;
	}
}
